<?php
require_once APPLICATION_PATH.'/../library/Sozfo/Form.php'; 
class Application_Form_Edit_Portfolio extends Sozfo_Form
{

    public $id = false;

    public function __construct($id) {
        $this->id = $id;
        parent::__construct();
    }

    public function init()
    {
        $this->setMethod('post');

        $languages = Application_Model_Language::getList();

        if (!empty($languages) && is_array($languages))
        {

            // Add input for key
            $code_validators = array(
                array('validator' => 'StringLength', 'options' => array(0, 128)),
            );
            $code_unique_validator = array('validator' => 'Db_NoRecordExists', 'options' => array('table' => 'portfolio', 'field' => 'code'));
            if ($this->id) {
                $code_unique_validator['options']['exclude'] = array(
                    'field' => 'id',
                    'value' => $this->id
                );
            }
            $code_validators[] = $code_unique_validator;
            $this->addElement('text', 'code', array(
                'label'      => 'Code',
                'required'   => true,
                'filters'    => array('StringTrim'),
                'validators' => $code_validators
            ));

            // Add input for status
            $this->addElement('checkbox', 'enabled', array(
                'label' => 'Enabled',
            ));

            foreach ($languages as $language)
            {
                // Add input for title
                $this->addElement('text', 'title_' . $language->getId(), array(
                    'label'      => 'Title',
                    'required'   => true,
                    'filters'    => array('StringTrim'),
                    'validators' => array(
                    )
                ));

                // Add input for description
                $this->addElement('tinyMce', 'description_' . $language->getId(), array(
                    'label'         => 'Description',
                    'required'      => true,
                    'cols'          => '50',
                    'rows'          => '10',
                    'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'moderator')
                ));
            }

            // Add input for icon
            $this->addElement('file', 'icon', array(
                'required'    => false,
                'label'       => 'Icon',
                'destination' => getcwd() . DIRECTORY_SEPARATOR . 'tmp',
                'validators'  => array(
                    array('IsImage', false),
                    array('Size', false, 1024 * 1024 * 5),
                    array('Upload', false),
                    array('imageSize', true, array(
                        'minheight' => 300,
                        'minwidth'  => 300,
                    ))
                ),
            ));
        }

    }
}

